package com.newsproject.mapper;


import com.newsproject.pojo.DTO.AccountUser;
import com.newsproject.pojo.DTO.OtherUserDTO;
import com.newsproject.pojo.User;

import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;


@Mapper
public interface UserMapper {



    /**
     * @param  param 包含email或userId的Map
     * @return User
     */
    User  selectUserByUserIdOrEmail(Map<String ,Object> param);
    /**
     * 根据邮箱或用户id查询用户信息
     * @param param 包含email或userId的Map
     * @return AccountUser
     */
    AccountUser findUserByEmailOrUserId(Map<String ,Object> param);


    /*
    * 添加用户
    * */
    @Insert("insert into user ( email, password ,username) values (#{email}, #{password},#{username})")
    void insertUser(@Param("email") String email, @Param("password") String password, @Param("username") String username);

    /**
    * 判断邮箱是否已经存在
    * */
    @Select("select  user_id from user where email = #{email}")
    Integer selectUserIdByEmail(String email);

    //更新密码
    boolean updatePassword(@Param("email")String email ,@Param("password") String newPassword);
    //更改个人信息
    boolean updateUserByUserId(@Param("user_id") int userId,@Param("username") String username,@Param("gender") int gender ,@Param("address") String address, @Param("introduction") String introduction,@Param("avatar") String avatar);

    boolean insertUserStatus(@Param("user_id") int userId);

    void insertVerificationRequest(@Param("user_id")int userId,@Param("apply_info") String apply_info);
    /**
    * 查看用户的认证申请状态
    * @Param("user_id") int userId 用户id
    * */
    int registerMember(@Param("user_id") int userId,@Param("is_member") int memberStatus);

    String selectApplyStatusByUserId(@Param("user_id")int userId);
    //查询所有用户的名字
    List<String> selectAllName();

    @Select("select verification_request.request_id from  verification_request where user_id = #{user_id}")
    Integer getVerificationRequestId(@Param("user_id") int userId);




    //增加或者减少关注数量
    @Update("update user  set likecount = likecount+1 where user_id = #{user_id}")
    void addBookmarkCount(@Param("user_id") int userId);
    @Update("update user  set likecount = likecount-1 where user_id = #{user_id}")
    void declineBookmarkCount(@Param("user_id") int userId);

    //增加或者减少粉丝数量
    @Update("update  user set follower_count = follower_count+1 where user_id = #{user_id}")
    void addFollowerCount(@Param("user_id") int userId);
    @Update("update  user set follower_count = follower_count-1 where user_id = #{user_id}")
    void declineFollowerCount(@Param("user_id") int userId);

    /**
     * 增加获赞数量
     * @param userId
     */
    @Update("update  user set prize = prize+1 where user_id = #{user_id}")
    void addPrizeCount(@Param("user_id") int userId);
    /**
     * 减少获赞数量
     * @param userId
     */
    @Update("update  user set prize = prize-1 where user_id = #{user_id}")
    void declinePrizeCount(@Param("user_id") int userId);


    //查询其他用户粉丝列表
    List<OtherUserDTO> selectFollowerList(@Param("userId") int userId,@Param("otherUserId")Integer otherUserId,@Param("startIndex") Integer startIndex);
    Integer countFollower(@Param("user_id") int userId);
    //查询其他用户关注列表
    List<OtherUserDTO> findFollowedList(@Param("user_id") int userId,@Param("otherUserId")Integer otherUserId,@Param("startIndex") Integer startIndex);
    Integer countFollowed(@Param("user_id") int userId);
    //查询其他用户的信息
    OtherUserDTO findOtherUserById(@Param("user_id") int userId,@Param("otherUserId")Integer otherUserId);
}
